package com.belizer.demo.threadpool;

import java.time.LocalDateTime;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Demo3 {

    public static void main(String[] args) {
        System.out.println(LocalDateTime.now());
        ExecutorService executorService = Executors.newFixedThreadPool(3);

        try{

            for(int i = 0; i < 100000; i++ ){
                final int j = i;
                executorService.execute(()->{
                    //模拟任务执行消耗
                    try {
                        TimeUnit.MICROSECONDS.sleep(100);
                        System.out.println(j);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                });
            }

        }finally {
            System.out.println("main method end,time is " + (LocalDateTime.now()) );
            executorService.shutdownNow();

            while (! executorService.isShutdown()){

            }

            if(executorService.isShutdown()){

            }
        }




    }
}
